package com.wxg.demo;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class SampleDemo102 {
	public static void main(String[] args) {
		code101();
	}
	
	/**
	 * Exception in thread "main" java.lang.IllegalStateException: 
	 * The path to the driver executable must be set by the webdriver.chrome.driver system property; 
	 * for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. 
	 * The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
	 * 
	 */
	public static void code101(){
		System.setProperty("webdriver.chrome.driver", "F:\\Downloads\\chromedriver_win32\\chromedriver.exe");
		WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com");
        WebElement element = driver.findElement(By.name("q"));
        element.sendKeys("Cheese!");
        element.submit();
        System.out.println("Page title is: " + driver.getTitle());
        
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });
        
        System.out.println("Page title is: " + driver.getTitle());
        driver.quit();
	}
}
